package com.study.java8;

import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author ysy
 * @version 1.0
 * @Title: ParallelArrayTest
 * @Note <b>ProjectName:</b> cusc-venus
 * <br><b>PackageName:</b> com.cusc.venus.acc.center.util
 * <br><b>ClassName:</b>
 * <br><b>Date:</b>
 *
 */
public class ParallelArrayTest {

    // 并行数组测试类
    public static void main(String[] args) {
        long[] arrayOfLong = new long[20000];

        // 使用parallelSetAll()方法生成20000个随机数
        Arrays.parallelSetAll(arrayOfLong, index -> ThreadLocalRandom.current().nextInt(1000000) );
        // 输出乱序的前10个
        Arrays.stream(arrayOfLong).limit(10).forEach(i -> System.out.print( i + " " ));
        System.out.println();

        //使用parallelSort()方法进行排序
        Arrays.parallelSort(arrayOfLong);
        // 输出排序的前10个
        Arrays.stream(arrayOfLong).limit(10).forEach(i -> System.out.print( i + " " ));
        System.out.println();
    }
}
